package com.wangjw.controller;

import com.wangjw.redis.RedisClient;
import com.wangjw.redis.RedisShardedPoolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wangjw on 18/6/4.
 */
@RestController
@RequestMapping("simple")
public class SimpleController {

    @Autowired
    private RedisClient redisClient;

    @RequestMapping("hello")
    public String hello() {
        return "hello redis";
    }

    @RequestMapping("redis-set")
    public String redisSet() {
        return redisClient.setEx("nijj", "yuwen", 500);
    }

    @RequestMapping("redis-get")
    public String redisGet() {
        return redisClient.get("wangjw");
    }

    @RequestMapping("sharded-redis-set")
    public String shardedRedisSet() {
        for (int i = 100; i < 200; i++) {
            RedisShardedPoolUtil.set("key-" + i, "value-" + i);
        }
        return "成功";
    }
}
